<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>留言表</title>
    <style>
        .input-item{
            margin-bottom: 1rem;
        }
    </style>
</head>
<body>
    <div id="app">
        
        <div class='input-item'><input type="text" style="width:180px;" v-model='msg.name'></div>
        <div class='input-item'><textarea name="" id="" cols="30" rows="10" style="width:180px;" v-model='msg.content'></textarea></div>
        <div class='input-item'> <button @click='handlePublish'>发布</button> </div>
        
        <!-- 留言列表 -->
        <ul v-if='list.length >0'>
            <li v-for='msg in list'>
                {{msg.name}}:{{msg.content}} 
                <br>
                <input type="text">
                <b @click='handleReply(msg)'>回复</b>
                <ul v-if='msg.replyList!=undefined && msg.replyList.length > 0'>
                    <li v-for='replyItem in msg.replyList'>
                        {{replyItem.name}}:{{replyItem.content}}
                    </li>
                </ul>
            </li>
        </ul>

    </div>
    
    <script src="./utils/vue.min.js"></script>
    
    </script>

    <script>
        var app = new Vue({
            el: '#app',
            data: {
                msg: {},
                list: [{name:'小张',content:'请问学习前端开发有什么好的方法？',replyList:[{name:'小美',content:'多看好书；勤练习；'}]}]
            },
            methods:{
                handlePublish: function(){
                    var msgCopy={};
                    msgCopy.name = this.msg.name;
                    msgCopy.content = this.msg.content;
                    this.list.push(msgCopy);
                },
                handleReply: function(msg){

                }
            }
        });
    </script>

</body>
</html>